package com.javabi.htmlbuilder.html.element.form;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLElementList;
import com.javabi.htmlbuilder.html.HTMLElementName;

/**
 * A Form Select Drop-Down Option.
 */
public class Option extends HTMLElementList<Option> {

	/** The value. */
	private Object value = null;
	/** Indicates if this option is selected. */
	private boolean selected = false;

	/**
	 * Returns the value
	 * @return the value
	 */
	public final Object getValue() {
		return value;
	}

	/**
	 * Sets the value
	 * @param value the value to set
	 */
	public final void setValue(Object value) {
		this.value = value;
	}

	/**
	 * Returns true if this option is selected
	 * @return true if this option is selected
	 */
	public final boolean isSelected() {
		return selected;
	}

	/**
	 * Sets whether or not this option is selected
	 * @param selected true to select this option
	 */
	public final void setSelected(boolean selected) {
		this.selected = selected;
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public HTMLElementName getElementName() {
		return HTMLElementName.OPTION;
	}

	/**
	 * Append this to the given html builder.
	 * @param html the html builder.
	 * @return the html builder.
	 */
	public HTMLBuilder appendAttributesTo(HTMLBuilder html) {
		if (value != null) {
			html.attribute("value", value);
		}
		if (selected) {
			html.attribute("selected", "true");
		}
		return html;
	}

}
